﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：资讯管理Ajax请求服务端处理程序。
  //创建人：赵国伟
  //生成时间：2012/03/18 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.BLL;
using Shopping.Model;

public partial class Manage_AS_NewsCommon : BaseManagePage
{
    private readonly NewsManage bllNews = new NewsManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["Action"] as string;
            switch (action)
            {
                case "SaveCategory":   //保存资讯类别； by 赵国伟 2012-03-29
                    SaveCategory();
                    break;
                case "GetCategoryInfo":  //获取资讯类别信息；by 赵国伟 2012-03-29
                    GetCategoryInfo();
                    break;
                case "DeleteCategory":  //删除指定的资讯类别； by 赵国伟 2012-03-29
                    DeleteCategory();
                    break;
                case "SaveNews":  //保存指定的资讯信息； by 赵国伟 2012-03-31
                    SaveNews();
                    break;
                case "GetNews":  //查询一条指定的资讯信息；by 赵国伟 2012-03-31
                    GetNews();
                    break;
                case "DeleteNews": //删除一条指定的资讯信息；by 赵国伟 2012-03-31
                    DeleteNews();
                    break;
            }
            Response.End();
        }
    }

    #region "保存资讯类别； by 赵国伟 2012-03-29"
    /// <summary>
    /// 保存资讯类别信息
    /// </summary>
    private void SaveCategory()
    {
        //获取客户端提交上来的数据；结构为json结构；
        string jsonData = Request["jsonData"] + "";  //获取传递过来的Json对象数据；
       
        NewsCategories info = null;
        ReturnValue ret = new ReturnValue();
        try
        {
            ///将提交上来的Json格式的数据装化为相应的实体类；
            info = JSONHelper.JsonStringToObject<NewsCategories>(jsonData);
        }
        catch (Exception e)
        {
            ret.Message = "数据提取失败！" + e.Message;
            Response.Write(ret.ToJsonString());
            return;
        }
        if (info != null)
            ret = bllNews.SaveCategory(info);
        else
            ret.Message = "提交数据不能为空！";
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "获取资讯类别信息；by 赵国伟 2012-03-29"
    /// <summary>
    /// 获取资讯类别信息
    /// </summary>
    private void GetCategoryInfo()
    {
        int CategoryID = Utility.G<int>("CategoryID");

        NewsCategories c = bllNews.GetCategoryInfo(CategoryID);
        if (c != null)
            Response.Write(c.ToJsonString());
    }
    #endregion

    #region "删除指定的资讯类别； by 赵国伟 2012-03-29"
    /// <summary>
    /// 删除指定的资讯类别
    /// </summary>
    private void DeleteCategory()
    {
        int CategoryID = Utility.G<int>("CategoryID");

        ReturnValue ret = new ReturnValue();
        if (CategoryID <= 0)
        {
            ret.Message = "资讯类别错误！";
        }
        else
        {
            if (bllNews.DeleteCategories(CategoryID) > 0)
            {
                ret.Result = ResultType.Success;
            }
            else
            {
                ret.Message = "未找到对应的资讯类别信息";
            }
        }
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "保存资讯信息； by 赵国伟 2012-03-31"
    /// <summary>
    /// 保存资讯信息；
    /// </summary>
    private void SaveNews()
    {
        //获取客户端提交上来的数据；结构为json结构；
        string jsonData = Request["jsonData"] + "";  //获取传递过来的Json对象数据；
        string Content = Utility.P("Content");
        News info = null;
        ReturnValue ret = new ReturnValue();
        try
        {
            ///将提交上来的Json格式的数据装化为相应的实体类；
            info = JSONHelper.JsonStringToObject<News>(jsonData);
        }
        catch (Exception e)
        {
            ret.Message = "数据提取失败！" + e.Message;
            Response.Write(ret.ToJsonString());
            return;
        }
        info.NewsContent = Content;
        if (info != null)
            ret = bllNews.SaveNews(info);
        else
            ret.Message = "提交数据不能为空！";
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条资讯信息； by 赵国伟 2012-03-31"
    /// <summary>
    /// 查询一条资讯信息；
    /// </summary>
    private void GetNews()
    {
        int NewsID = Utility.G<int>("NewsID");
        NewsInfo d = bllNews.GetNews(NewsID);
        if (d != null)
            Response.Write(JSONHelper.ObjectToJson<NewsInfo>(d));
    }
    #endregion

    #region "删除一条资讯信息 by 赵国伟 2012-03-31"
    /// <summary>
    /// 删除一条资讯信息
    /// </summary>
    private void DeleteNews()
    {
        int NewsID = Utility.G<int>("NewsID");
        Response.Write(bllNews.DeleteNews(NewsID).ToJsonString());
    }
    #endregion





}